from collections import OrderedDict

from django.shortcuts import render
from django.views import View

from apps.contents.models import ContentCategory
from apps.goods.models import GoodsChannel


class IndexView(View):
    def get(self,request):
        #首页展示广告
        contents = {}
        #1.取出所有的广告类
        contents_categories = ContentCategory.objects.all()
        for cat in contents_categories:
            contents[cat.key] = cat.content_set.filter(status=True).order_by("sequence")

        #商品频道和分类
        from apps.contents.utils import get_categories
        categories = get_categories()
            #构造渲染模板所需要的数据格式
        context = {
                'categories':categories,#商品频道和内容
                "contents":contents,  #广告
            }
        return render(request,"index.html",context)